﻿(function($) {
    var config;
    var menuConfig;
    var configTitles;
    //var filterContainer = [{
    //    "title": "channelId",
    //    "value": 'F6E13FB8-2ACF-E111-AD87-842B2B516531'
    //}];
    $.reportFramework = {
        renderPage: function() {
            initialConfig();
            frameworkRender();
        }
    }
    var filterContainer = [];
    var excelPromises = [];
    var isExportExcelAll = false;
    var excelExportInterval;
    var popupNotification;
    var frameLayoutMainIds = { "titleId": "rf_Title", "mainId": "rf_Main", "normalQueryId": "rf_NormalQuery", "listToolBar": "rf_ListToolBar", "dataListId": "rf_DataList" };
    var frameLayoutMainCsss = { "normalQueryItem": "rf_nq_item" };

    function initialConfig() {
        kendo.culture('zh-CN');
        var qurl = "/Home/GetConfigClient";
        try {
            $.ajax({
                type: "POST",
                async: false,
                contentType: "application/json",
                url: qurl,
                dataType: "json",
                success: function(data) {
                    config = data.client;
                    menuConfig = data.menu;
                },
                error: function(e) {
                    console.error(e.message);
                }
            });
        } catch (e) {
            console.error(e.message);
        }
        filterContainer = [];
        excelPromises = [];
        isExportExcelAll = false;
        window.clearInterval(excelExportInterval);
        configTitles = [];
    }

    function frameworkRender() {
        leftMenuRender();
        barRender();
        if (config && config.InternalName) { //Render report
            reportRender();
        } else {
            contentMenuRender();
        }
        $(".page-content").find("a[path]").bind("click", function() {
            ajaxLoadReportContent($(this).attr("path"));
        });
    }

    function leftMenuRender() {
        var $thisParent = $(".page-sidebar-menu");
        var $newDiv = $("<div>");
        //$thisParent.html("");
        if (menuConfig && menuConfig.length > 0) {
            var queryResult = Enumerable.from(menuConfig)
                .where(function(x) {
                    return x.ParentId == 1;
                })
                .toArray();
            leftMenuRenderRecursion($newDiv, queryResult);
        }
        //$thisParent.empty();
        $thisParent.find("li:not(:first)").empty();
        $newDiv.children().appendTo($thisParent);
    }

    function leftMenuRenderRecursion($parent, array) {
        $.each(array, function(i, obj) {
            var $li;
            var $oLia = $(".page-sidebar-menu").find("a[href='" + obj.Url + "']");
            if ($oLia.length > 0) {
                $li = $oLia.parent();
            } else {
                var startClass;
                var faIcon;
                var link = obj.Url;
                var title = obj.Title;
                if (obj.ParentId == null) {
                    startClass = "start";
                    faIcon = "fa-home";
                } else {
                    startClass = "";
                    faIcon = "fa-cogs";
                }
                $li = $("<li>").addClass(startClass);
                var $link = $("<a class='ajaxify'></a>").addClass(startClass).attr("href", link);
                var $icon = $("<i class='fa'></i>").addClass(faIcon);
                var $title = $("<span class='title'></span>").text(title);
                var $selected = $("<span class='selected'></span>");
                $icon.appendTo($link);
                $title.appendTo($link);
                $selected.appendTo($link);
                $link.appendTo($li);

                var queryResult = Enumerable.from(menuConfig)
                    .where(function(x) {
                        return x.ParentId == obj.Id;
                    })
                    .toArray();
                if (queryResult.length > 0) {
                    $link.removeClass("ajaxify");
                    var $arrow = $("<span class='arrow'></span>");
                    var $newUl = $("<ul class='sub-menu'></ul>");
                    $arrow.appendTo($link);
                    $newUl.appendTo($li);
                    leftMenuRenderRecursion($newUl, queryResult);
                }
            }
            $li.appendTo($parent);
        });
    }

    function contentMenuRender() {
        var $topParent = $("#" + frameLayoutMainIds.dataListId);
        var dispConfig = {
            dataSource: {
                data: config,
                schema: {
                    model: {
                        id: "Id",
                        fields: {
                            parentId: { field: "ParentId", nullable: true }
                        },
                        expanded: true
                    }
                }
            },
            columns: [
                {
                    field: "Title",
                    title: "报表名",
                    width: "280px",
                    template: function(dataItem) {
                        if (dataItem.Url != "") {
                            return "<a path=\"" + dataItem.Url + "\">" + dataItem.Title + "</a>";
                        } else {
                            return dataItem.Title;
                        }
                    }
                },
                {
                    field: "Proposer",
                    title: "提出者",
                    width: "80px"
                },
                {
                    field: "DateOfPresentation",
                    title: "提出日期",
                    width: "100px"
                },
                {
                    field: "Description",
                    title: "描述"
                }
            ]
        };
        $topParent.kendoTreeList(dispConfig);
    }

    function barRender() {
        builtPageBar();
    }

    function reportRender() {
        //add body class tag
        $('body').addClass(config.InternalName);
        //render filters
        bindNormalFilters();
        //render data lists
        bindDataLists();
    }

    function builtPageBar() {
        var rfTitle = $("<div>").attr("id", frameLayoutMainIds.titleId);
        $("#" + frameLayoutMainIds.mainId).before(rfTitle);
        var pageTitle = $("<h3>").addClass("page-title").text("RMS报表管理系统");
        var pageBar = $("<div>").addClass("page-bar");
        var pageBreadcrumb = $("<ul>").addClass("page-breadcrumb");
        var $li = $("<li>").appendTo(pageBreadcrumb);
        var $liContent = $("<i class='fa fa-home'></i><a path='/Home/Report'>主页</a>");
        $liContent.appendTo($li);
        var pathNames = window.location.hash.replace("#", "").split('/');
        if (pathNames != "") {
            var path = "/";
            $.each(pathNames, function(i, obj) {
                path += "/" + obj;
                path = path.replace("//", "/");
                if (obj != "" && isContainChina(obj)) {
                    $li = $("<li>").appendTo(pageBreadcrumb);
                    $liContent = $("<i class='fa fa-angle-right'></i><a path='" + path + "'>" + obj + "</a>");
                    $liContent.appendTo($li);
                }
            });
        }
        var pageToolBar = $("<div>").addClass("page-toolbar");
        var actionGroup = $("<div>").attr("class", "btn-group pull-right");
        var actionTitle = $("<button type='button' class='btn btn-fit-height grey-salt dropdown-toggle' data-toggle='dropdown' data-hover='dropdown' data-delay='1000' data-close-others='true'>操作 <i class='fa fa-angle-down'></i></button>")
        var actionList = $("<ul class='dropdown-menu pull-right' role='menu'>");
        var actionListItem_ExcelExport = $("<li>").append($("<a href='#'><i class='k-icon k-i-excel'> </i> 导出Excel</a>").click(function() {
            exportAllToExcel();
        }));
        pageTitle.appendTo(rfTitle);
        pageBar.appendTo(rfTitle);
        pageBreadcrumb.appendTo(pageBar);
        pageToolBar.appendTo(pageBar);
        actionGroup.appendTo(pageToolBar);
        actionTitle.appendTo(actionGroup);
        actionList.appendTo(actionGroup);
        actionListItem_ExcelExport.appendTo(actionList);
    }

    function onFilterChange(titleValue) {
        var queryResult = Enumerable.from(filterContainer)
            .where(function(x) {
                return x.title != titleValue.title;
            })
            .toArray()
            .concat(titleValue);
        filterContainer = queryResult;
        bindDataListsOnly();
    }

    function bindDataLists() {
        var gridTitles = [];
        var dataListConfigObj = config.dataLists;
        var $topParent = $("#" + frameLayoutMainIds.dataListId);
        if (dataListConfigObj.length > 1) {
            var $ul = $('<ul>');
            $ul.appendTo($topParent);
            $.each(dataListConfigObj, function(i, obj) {
                var $div = $("<div>").addClass("rf_datalist_item").appendTo($topParent);
                $("<li>" + obj.title + "</li>").appendTo($ul);
                bindDataList(obj, $div);
                gridTitles[i - 1] = obj.title;
            });
            bindExcelExport($ul);
            $topParent.kendoTabStrip({
                animation: {
                    open: {
                        effects: "fadeIn"
                    }
                }
            }).data("kendoTabStrip").select(0);
        } else if (dataListConfigObj.length == 1) {
            var $div1 = $("<div>").addClass("rf_datalist_item");
            $div1.appendTo($topParent);
            bindDataList(dataListConfigObj[0], $div1);
            gridTitles[0] = dataListConfigObj[0].title;
        }
        configTitles = { "gridTitles": gridTitles };
    }

    //已停用
    function bindExcelExport($parent) {
        //var $exportExcel = $("<button>").addClass("export-excel-all").text("导出所有excel");
        //$exportExcel.appendTo($("<li></li>")).appendTo($parent);
        //$exportExcel.kendoButton({
        //    spriteCssClass: "k-icon k-i-excel",
        //    click: function () {
        //        exportAllToExcel();
        //    }
        //});
    }

    function exportAllToExcel() {
        showPopupNotification("正在导出中，请稍后...");
        isExportExcelAll = true;
        var $topParent = $("#" + frameLayoutMainIds.dataListId);
        var datalistObjs = $topParent.find(".k-grid");
        var count = 0;
        if (datalistObjs.length > 0) {
            $.each(datalistObjs, function(i, obj) {
                //$(obj).data("kendoGrid").saveAsExcel();
                recursiveSaveAsExcel($(obj));
                count++;
            });
            window.clearInterval(excelExportInterval);
            var timeRecord = 0;
            excelExportInterval = setInterval(function() {
                timeRecord += 100;
                if (excelPromises.length >= count) {
                    window.clearInterval(excelExportInterval);
                    exportToExcel();
                    if (popupNotification) popupNotification.hide();
                    isExportExcelAll = false;
                }
            }, 100);
        } else {
            if (popupNotification) popupNotification.hide();
            isExportExcelAll = false;
        }
    }

    function recursiveSaveAsExcel($obj) {
        var grid = $obj.data("kendoGrid");
        if (grid._data) {
            grid.saveAsExcel();
        } else {
            setTimeout(function() {
                recursiveSaveAsExcel($obj);
            }, 2000);
        }
    }

    function showPopupNotification(notificationStr) {
        if (popupNotification) popupNotification.hide();
        $("<span>").attr("id", "popupNotification").appendTo($("body"));
        popupNotification = $("#popupNotification").kendoNotification({
            autoHideAfter: 0
        }).data("kendoNotification");
        popupNotification.show(notificationStr, "info");
    }

    function exportToExcel() {
        var sheets = [];
        var flag = true;
        $.each(excelPromises, function(i, obj) {
            var array = [];
            var excelTitle;
            for (var key in obj) {
                excelTitle = key;
                array[0] = obj[key];
            }
            $.when.apply(null, array)
                .then(function(data) {
                    // create a new workbook using the sheets of the products and orders workbooks
                    if (data.sheets[0].rows.length <= 50000) {
                        var sheetTitle = { title: excelTitle }
                        $.extend(true, data.sheets[0], sheetTitle);
                        sheets[i] = data.sheets[0];
                    } else {
                        flag = false;
                    }
                });
        });
        excelPromises = [];
        var workbook = new kendo.ooxml.Workbook({
            sheets: sheets
        });
        if (flag) {
            try {
                // save the new workbook,b
                kendo.saveAs({
                    dataURI: workbook.toDataURL(),
                    fileName: "ReportFramework_Export_excel.xlsx"
                });
            } catch (e) {
                workbook = null;
                CollectGarbage();
                alert('超出excel导出数据极限！');
            }
        } else {
            alert('单表导出excel数目不能大于50000条！');
        }
    }

    function bindDataListsOnly() {
        var dataListConfigObj = config.dataLists;
        var $topParent = $("#" + frameLayoutMainIds.dataListId);
        var datalistObjs = $topParent.find(".rf_datalist_item");
        $.each(dataListConfigObj, function(i, obj) {
            kendo.destroy(obj);
            bindDataList(obj, datalistObjs.eq(i));
        });
    }

    function bindDataList(obj, $parent) {
        //$parent.find('.k-grid').eq(0).empty();
        var schema = {
            data: "data",
            total: "data.length"
        }
        var dataSourceJson = {
            transport: {
                read: function(options) {
                    $.ajax({
                        type: "POST",
                        async: true,
                        url: obj.dataSource.url,
                        dataType: 'text',
                        data: {
                            "spFuncName": obj.dataSource.spFuncName,
                            "filterStr": JSON.stringify(filterContainer),
                            "filterToFields": obj.filterToFields //fieldcontrolid1:field1,fieldcontrolid1:field2
                        },
                        success: function(data) {
                            try {
                                if ($.browser.msie) {
                                    options.success($.parseJSON(data));
                                } else {
                                    options.success(json_parse(data));
                                }
                            } catch (e) {
                            }
                        },
                        error: function(e) {
                            console.error(e.message);
                        }
                    });
                }
            },
            schema: schema,
            pageSize: 25
        };
        if (obj.dataSource.kendoDataSource) {
            $.each(obj.dataSource.kendoDataSource, function(key, value) {
                if (dataSourceJson[key]) {
                    $.extend(true, dataSourceJson[key], value);
                } else {
                    dataSourceJson[key] = value;
                }
            });
        }
        var dataSource = new kendo.data.DataSource(dataSourceJson);
        var dispConfig = obj.kendoOtherCofigs;
        var commonConfigInitial = {
            "编辑": { editable: dispConfig.editable && dispConfig.editable!='true' ? dispConfig.editable : false },
            "分组": { groupable: dispConfig.groupable && dispConfig.groupable != 'true' ? dispConfig.groupable : false },
            "排序": { sortable: dispConfig.sortable && dispConfig.sortable != 'true' ? dispConfig.sortable : false },
            "过滤": { filterable: dispConfig.filterable && dispConfig.filterable != 'true' ? dispConfig.filterable : false },
            "列排序": { reorderable: dispConfig.reorderable && dispConfig.reorderable != 'true' ? dispConfig.reorderable : false },
            "列拖拽": { resizable: dispConfig.resizable && dispConfig.resizable != 'true' ? dispConfig.resizable : false },
            "可复制": { allowCopy: dispConfig.allowCopy && dispConfig.allowCopy != 'true' ? dispConfig.allowCopy : false },
            "可选择": { selectable: dispConfig.selectable && dispConfig.selectable != 'true' ? dispConfig.selectable : false }
        };
        var defaultConfig = {
            //toolbar: ["excel"],
            //toolbar: kendo.template("<div></div>"),
            excel: {
                fileName: "ReportFramework_Export_excel.xlsx",
                filterable: true,
                allPages: true
            },
            excelExport: function(e) {
                var title = e.sender.options.title;
                if (!excelPromises[title]) {
                    showPopupNotification("正在导出" + title + "，请稍后...");
                    e.preventDefault();
                    var deferred = $.Deferred().resolve(e.workbook);
                    var thisObj = {};
                    thisObj[title] = deferred.resolve(e.workbook);
                    excelPromises[excelPromises.length] = thisObj;
                    if (!isExportExcelAll) {
                        setTimeout(function() {
                            exportToExcel();
                            if (popupNotification) popupNotification.hide();
                        }, 0);
                    }
                }
            },
            dataSource: dataSource,
            filterable: true,
            sortable: true,
            resizable: true,
            //groupable: true,
            //columnMenu: true,
            //selectable: "multiple cell",
            //allowCopy: true,
            //reorderable: true,
            pageable: {
                refresh: true,
                pageSizes: [10, 25, 50, 90],
                buttonCount: 10
            },
            scrollable: true,
            title: obj.title,
            commonConfigInitial: commonConfigInitial
        };
        $.extend(true, defaultConfig, dispConfig);
        try {
            $parent.find("*").unbind();
        } catch (e) {
        }

        var $griddiv;
        if ($parent.find(".k-grid").length > 0) {
            $griddiv = $parent.find(".k-grid").eq(0);
            var grid = $griddiv.data("kendoGrid");
            grid.destroy();
            $griddiv.empty().kendoGrid(defaultConfig);
        } else {
            $griddiv = $("<div>").appendTo($parent);
            $griddiv.kendoGrid(defaultConfig);
        }

        bindGridToolbar($parent);
    }

    function bindGridToolbar($parent) {
        $parent.removeClass("k-content").addClass("k-content");
        var $toolbar = $parent.find(".k-toolbar");
        if ($toolbar.length > 0) {
            var toolbar = $toolbar.data("kendoToolBar");
            var options = toolbar.options;
            toolbar.destroy();
            $toolbar.empty().kendoToolBar(options);
        } else {
            bindGridToolbar_CreateNew($parent);
        }

        //export excel
        $parent.find(".exportToExcel").off("click").on("click", function() {
            var $grid = $(this).parents('.k-toolbar').eq(0).next('.k-grid');
            $grid.data("kendoGrid").saveAsExcel();
        });

        //common config action
        $parent.find(".grid_common_config").off("click").on("click", function() {
            gridToolbarChange($(this).parents('.k-toolbar').eq(0));
        });

        //fullscreen action
        $parent.find(".fullscreen").off("click").on('click', function() {
            var $toolbar = $(this).parents('.k-toolbar').eq(0);

            //for tab cotent
            var $portlet = $toolbar.parents('.portlet').eq(0);
            if ($portlet.hasClass("k-content")) {
                $(this).find("span").removeClass("k-i-maximize").addClass("k-i-restore");
                $portlet.removeClass("k-content");
            } else {
                $(this).find("span").removeClass("k-i-restore").addClass("k-i-maximize");
                $portlet.addClass("k-content");
            }

            //refresh grid to fit specific situation
            setTimeout(function() {
                var $grid = $toolbar.next('.k-grid');
                var grid = $grid.data("kendoGrid");
                var options = grid.options;
                grid.destroy();
                $grid.empty().kendoGrid(options);
            }, 0);
        });

        //column
        $parent.find(".grid_columns").kendoDropDownList({
            optionLabel: "Paragraph",
            dataTextField: "text",
            dataValueField: "value",
            dataSource: [
                { text: "Heading 1", value: 1 },
                { text: "Heading 2", value: 2 },
                { text: "Heading 3", value: 3 },
                { text: "Title", value: 4 },
                { text: "Subtitle", value: 5 }
            ]
        });
    }

    function bindGridToolbar_CreateNew($parent) {
        var $grid = $parent.find(".k-grid");
        $parent.addClass("portlet");
        var $toolbar = $("<div>").addClass("portlet-title").insertBefore($grid);
        $grid.addClass("portlet-body");
        $toolbar.kendoToolBar({
            resizable: false,
            items: [
                { type: "button", text: "导出Excel", icon: "excel", attributes: { "class": "exportToExcel" } },
                { type: "separator" },
                {
                    type: "buttonGroup",
                    buttons: [
                        { icon: "pencil", text: "编辑", togglable: true, attributes: { "class": "grid_common_config" } },
                        { icon: "group", text: "分组", togglable: true, attributes: { "class": "grid_common_config" } },
                        { icon: "sort-asc", text: "排序", togglable: true, attributes: { "class": "grid_common_config" } ,selected: true},
                        { icon: "funnel", text: "过滤", togglable: true, attributes: { "class": "grid_common_config" }, selected: true },
                        { icon: "unpin", text: "列排序", togglable: true, attributes: { "class": "grid_common_config" } },
                        { icon: "resize-se", text: "列拖拽", togglable: true, attributes: { "class": "grid_common_config" }, selected: true },
                        { icon: "vbars", text: "可复制", togglable: true, attributes: { "class": "grid_common_config" } },
                        { icon: "tick", text: "可选择", togglable: true, attributes: { "class": "grid_common_config" }}
                    ]
                },
                //{ type: "separator" },
                //{ template: "<label>显示列:</label>" },
                //{
                //    template: "<input class='grid_columns' style='width: 150px;' />",
                //    overflow: "never"
                //},
                { type: "button", icon: "maximize", attributes: { "class": "fullscreen toolbar_maximize" } }
            ]
        });
    }

    function bindGridToolbar_UpdateConfig() {
        
    }

    function getGridConfigsFromToolbar($toolbar, commonConfigInitial) {
        var commonConfig= {},commonConfigSelected;
        commonConfigSelected = $toolbar.find(".grid_common_config.k-state-active").text();
        $.each(commonConfigInitial, function (i, obj) {
            if (commonConfigSelected.indexOf(i) > -1) {
                var objClone = {}
                if (i == '可选择') {
                    objClone[Object.keys(obj)[0]] = "multiple cell";
                } else {
                    objClone[Object.keys(obj)[0]] = true;
                }
                $.extend(true, commonConfig, objClone);
            } else {
                $.extend(true, commonConfig, obj);
            }
        });
        return commonConfig;
    }

    function gridToolbarChange($toolbar) {
        var $grid = $toolbar.next(".k-grid");
        var grid = $grid.data("kendoGrid");
        var options = grid.options;
        grid.destroy();
        var configs = getGridConfigsFromToolbar($toolbar, options.commonConfigInitial);
        $.extend(true, options, configs);
        $grid.empty().kendoGrid(options);
    }

    function bindNormalFilters() {
        var normalFiltersObj = config.normalFilters;
        $.each(normalFiltersObj, function (i, obj) {
            try {
                var f = eval("(function()　{return　(" + "ctrBind_" + obj.ctrlType + ");})()");
                f.call(this, obj);
               
            } catch (e) {

            }
        });
        $("<div>").css("clear", "both").appendTo($("#" + frameLayoutMainIds.normalQueryId));
    }

    function ctrBind_ComboBoxAutoComplete(configObj) {
        var filterVal = {};
        var ctrHtml = $("<div class='rf_nq_item " + configObj.field + "_class'><label for='" + configObj.field + "'>" + configObj.labelName + "：</label><input id='" + configObj.field + "' /></div>");
        ctrHtml.appendTo($("#" + frameLayoutMainIds.normalQueryId));
        var dataSource = new kendo.data.DataSource({
            serverFiltering: true,
            transport: {
                read: {
                    dataType: "json",
                    url: configObj.dataSource.url,
                    type: "POST"
                },
                parameterMap: function (options, operation) { // send value of autocomplete as the "startsWith" parameter
                    return {
                        "spFuncName": configObj.dataSource.spFuncName,
                        "filterStr": JSON.stringify(filterVal)
                    }
                }
            }
        });
        var defaultConfig = {
            minLength: 1,
            dataSource: dataSource,
            filter: "contains",
            filtering: function (e) {
                try {
                    filterVal = {
                        "title": e.filter.field,
                        "value": e.filter.value
                    };
                } catch (ex) {

                }
            },
            change: function (e) {
                var value = this.value();
                var keyValue = {
                    "title": configObj.field,
                    "value": value
                };
                onFilterChange(keyValue);
            }
        };

        var dispConfig = configObj.kendoMustConfigs;
        $.extend(true, dispConfig, configObj.kendoOtherConfigs);
        $.extend(true, dispConfig, defaultConfig);
        $("#" + configObj.field).kendoComboBox(dispConfig);
    }

    function ctrBind_DatePicker(configObj) {
        var ctrHtml = $("<div class='rf_nq_item  " + configObj.field + "_class''><label for='" + configObj.field + "'>" + configObj.labelName + "：</label><input id='" + configObj.field + "' /></div>");
        ctrHtml.appendTo($("#" + frameLayoutMainIds.normalQueryId));
        var defaultConfig = {
            format: "yyyy-MM-dd",
            change: function (e) {
                var value = new Date(this.value()).format('yyyy-MM-dd');
                value = value != "1970-01-01" ? value : "";
                var keyValue = {
                    "title": configObj.field,
                    "value": value
                };
                onFilterChange(keyValue);
            }
        };
        var dispConfig = configObj.kendoOtherConfigs;
        $.extend(true, dispConfig, defaultConfig);
        $("#" + configObj.field).kendoDatePicker(dispConfig);
    }

    function ctrBind_DropDownList(configObj) {
        var ctrHtml = $("<div class='rf_nq_item  " + configObj.field + "_class''><label for='" + configObj.field + "'>" + configObj.labelName + "：</label><input id='" + configObj.field + "' /></div>");
        ctrHtml.appendTo($("#" + frameLayoutMainIds.normalQueryId));
        var dataSource = new kendo.data.DataSource(configObj.dataSource.data ? { data: configObj.dataSource.data } : {
            transport: {
                read: {
                    dataType: "json",
                    url: configObj.dataSource.url,
                    type: "POST"
                },
                parameterMap: function (options, operation) { // send value of autocomplete as the "startsWith" parameter
                    return {
                        "spFuncName": configObj.dataSource.spFuncName,
                        "filterStr": "{}"
                    }
                }
            }
        });

        var defaultConfig = {
            dataSource: dataSource,
            change: function (e) {
                var value = this.value();
                var keyValue = {
                    "title": configObj.field,
                    "value": value
                };
                onFilterChange(keyValue);
            }
        };
        var dispConfig = configObj.kendoMustConfigs;
        $.extend(true, dispConfig, configObj.kendoOtherConfigs);
        $.extend(true, dispConfig, defaultConfig);
        $("#" + configObj.field).kendoDropDownList(dispConfig);
    }

    function ctrBind_GoSearch(configObj) {
        var ctrHtml = $("<div class='rf_nq_item  " + configObj.field + "_class''><label  for='" + configObj.field + "'>" + configObj.labelName + "：</label></div>");
        var $span = $("<span>").addClass("jq_gosearch").css({"float":"right"}).appendTo(ctrHtml);
        ctrHtml.appendTo($("#" + frameLayoutMainIds.normalQueryId));
        $span.goSearch({
            enableFuzzy: false,
            enableChoosePanel:false,
            id: configObj.field,
            onSearch: function () {
                var value = $("#" + configObj.field).val();
                var keyValue = {
                    "title": configObj.field,
                    "value": value
                };
                 onFilterChange(keyValue);
            }
        });
    }

    Date.prototype.format = function (format) {
        var o = {
            "M+": this.getMonth() + 1, //month
            "d+": this.getDate(),    //day
            "h+": this.getHours(),   //hour
            "m+": this.getMinutes(), //minute
            "s+": this.getSeconds(), //second
            "q+": Math.floor((this.getMonth() + 3) / 3),  //quarter
            "S": this.getMilliseconds() //millisecond
        }
        if (/(y+)/.test(format)) format = format.replace(RegExp.$1,
        (this.getFullYear() + "").substr(4 - RegExp.$1.length));
        for (var k in o) if (new RegExp("(" + k + ")").test(format))
            format = format.replace(RegExp.$1,
            RegExp.$1.length == 1 ? o[k] :
            ("00" + o[k]).substr(("" + o[k]).length));
        return format;
    }

    function isContainChina(str) {
        if (/.*[\u4e00-\u9fa5]+.*$/.test(str)) {
            return true;
        }
        return false;
    }

    function ajaxLoadReportContent(url) {
        Metronic.scrollTop();

        var pageContent = $('.page-content');
        var pageContentBody = $('.page-content .page-content-body');
        try {
            kendo.destroy(pageContentBody);
        } catch (e) {

        } 

        Metronic.startPageLoading();

        if (Metronic.getViewPort().width < 992 && $('.page-sidebar').hasClass("in")) { // close the menu on mobile view while laoding a page 
            $('.page-header .responsive-toggler').click();
        }
        window.location.hash = url;
        $.ajax({
            type: "GET",
            cache: false,
            url: url,
            dataType: "html",
            success: function (res) {
                Metronic.stopPageLoading();
                pageContentBody.html(res);
                Layout.fixContentHeight(); // fix content height
                Metronic.initAjax(); // initialize core stuff
            },
            error: function (xhr, ajaxOptions, thrownError) {
                pageContentBody.html('<h4>没有可显示的内容.</h4>');
                Metronic.stopPageLoading();
            }
        });
    }
})(jQuery);